mixin.ts ➔ created   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
ccs 20
cts 20
cp 1
rs 9.65
c 0
b 0
f 0
cc 3
crap 3
1 1
import type { ComponentOptionsMixin, CreateComponentPublicInstance } from 'vue';
2 1
import { isFunction } from './utils';
3 1
4 1
/**
5 1
 * Mixin, to be used in options API
6 1
 * Can be used locally or registered globally using `mixin: true`
7 1
 */
8 1
const pageTitleMixin: ComponentOptionsMixin = {
9 1
  created(this: CreateComponentPublicInstance) {
10 7
    const { title } = this.$options;
11 7
12 7
    if (title === undefined) {
13 3
      return;
14 3
    }
15 3
16 3
    // allow use dinamic title system
17 7
    if (isFunction(title)) {
18 2
      this.$watch(
19 2
        () => title.call(this, this),
20 2
        (val: string) => {
21 3
          this.$setPageTitle(val);
22 3
        },
23 2
        { immediate: true }
24 2
      );
25 2
      return;
26 2
    }
27 2
28 2
    this.$setPageTitle(title);
29 2
  },
30 7
};
31 1
32
export { pageTitleMixin };
33